package backstage.app.controller.upload;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import backstage.app.entity.layui.LayEdit;
import backstage.app.upload.service.NginxService;

/**
 * @author 测试
 */
@RestController
@RequestMapping("${spring.application.name}/upload/api")
public class UploadController {


	@Autowired
	private NginxService nginxService;




	/**
	 * 可上传图片、视频，只需在nginx配置中配置可识别的尾缀
	 */
	@SuppressWarnings("rawtypes")
	@PostMapping("/upload")
	public LayEdit pictureUpload(@RequestParam(value = "file") MultipartFile uploadFile) {
		Object result;
	try{
		  result = nginxService.uploadPicture(uploadFile);
		return LayEdit.ok(result.toString(),"成功");
	}catch (Exception e){
		result="http://dreamwang.com.cn/image/20201222/1608623064339892.jpg";
		return LayEdit.fall(result.toString(),"服务器异常请通知管理员");
	}

	}


	@PostMapping("/nolayui/upload")
	public String picturenoUpload(@RequestParam(value = "file") MultipartFile file) {
		Object result = null;
	try{
		  result = nginxService.uploadPicture(file);
		  return result.toString();
	}catch (Exception e){
		  return result.toString();
	}

	}


}
